*Figure A2: Share of households with <=3 year old child with parent in age at birth window, 1940 to 1970
clear
use ${data_dir}census_data

ren sploc _pernum
ren pernum sploc
ren _pernum pernum
ren marst spouse_marst
ren agemarr spouse_agemarr
ren durmarr spouse_durmarr
ren age spouse_age
ren sex spouse_sex


keep year serial pernum sploc spouse*

tempfile spouse
save `spouse'

use ${data_dir}census_data

keep year sex age nchild eldch yngch durmarr agemarr perwt hhwt sploc marst pernum serial subfam 

merge 1:1 year serial pernum sploc using `spouse'
 keep if (_merge==3 & sex==1) | _merge==1
 
keep if yngch<=3 

gen age_diff = age-spouse_age 
gen wife_older = age_diff<0
gen wife_gap = spouse_age-age if age_diff<0


gen dad_age_atBirth_yng = age-yngch if sex==1
gen mom_age_atBirth_yng = spouse_age-yngch if sex==1
 replace mom_age_atBirth_yng = age-yngch if sex==2
 
gen singleMom = sex==2 & nchild>0
gen singleDad = sex==1 & _merge==1 & nchild>0

gen dadInRange_yng = dad_age_atBirth_yng>=26 & dad_age_atBirth_yng<=47
gen momInRange_yng = mom_age_atBirth_yng>=10 & mom_age_atBirth_yng<=31
gen oneInRange_yng = dadInRange_yng | momInRange_yng

collapse (mean) dadInRange_yng-oneInRange_yng [w=hhwt], by(year)

tsset year
graph twoway tsline  oneInRange_yng, xtitle("Census") ytitle("Share of Households") ///
 graphregion(color(white))  ylabel(0.9(0.05)1, nogrid) 
 
graph export ${results_dir}figureA2.png, replace

exit
